package zhihui.mobile.ui.express;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;

import com.google.gson.Gson;

import org.json.JSONObject;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;
import zhihui.mobile.R;
import zhihui.mobile.bean.express.ExpressBeanListV2;
import zhihui.mobile.interfaces.net.IHttpCallBackListener;
import zhihui.mobile.manager.express.ExpressManager;
import zhihui.mobile.manager.user.UserManager;
import zhihui.mobile.presenter.IPresenter;
import zhihui.mobile.ui.BaseFragment;

/**
 * Created by Administrator on 2017/9/16.
 */

public class SendOffExpressFragment extends BaseFragment {
    @Bind(R.id.express_rv)
    RecyclerView expressRv;

    ExpressHistorySendAdapter adapter;

    @Override
    public void initView() {

    }

    @Override
    protected int getLayoutResId() {


        return R.layout.exprees_send_off_fragment;
    }

    @Override
    protected IPresenter[] getPresenters() {
        return new IPresenter[0];
    }

    @Override
    protected void onInitPresenter() {

    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View rootView = super.onCreateView(inflater, container, savedInstanceState);
        ButterKnife.bind(this, rootView);
        return rootView;
    }

    @Override
    public void onResume() {
        super.onResume();
        initData();
    }


    private void initData() {
        expressRv.setLayoutManager(new LinearLayoutManager(getActivity()) {
            @Override
            public boolean canScrollVertically() {
                return false;
            }
        });
        expressRv.setHasFixedSize(true);


        ExpressManager.getInstance().initExpressList(new IHttpCallBackListener() {
            @Override
            public void success(JSONObject result) {
                Gson gson = new Gson();
                ExpressBeanListV2 historyBeanList = gson.fromJson(result.toString(), ExpressBeanListV2.class);
                adapter = new ExpressHistorySendAdapter(historyBeanList.getData().getOuter(), getActivity());
                expressRv.setAdapter(adapter);
            }

            @Override
            public void failed(String message) {
                com.zgm.utils.UiUtils.ToastInCenter(getActivity(), message, Toast.LENGTH_SHORT);
            }
        }, UserManager.getInstance().getCurUser().getNo());
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        ButterKnife.unbind(this);

    }

    @OnClick(R.id.send_off_exproess_tv)
    public void onViewClicked() {
        startActivity(new Intent().setClass(getActivity(), SendOffExpressActivity.class));
    }
}
